
/**
 * 判断是否为空对象
 * @param {*} object 源对象
 */
export function isEmptyObject (object) {
  return Object.keys(object).length === 0
}

/**
 * 判断是否为对象
 * @param {*} object
 */
export function isObject (object) {
  return Object.prototype.toString.call(object) === '[object Object]'
}

/**
 * 判断是否为对象
 * @param {*} array
 */
export function isArray (array) {
  return Object.prototype.toString.call(array) === '[object Array]'
}

/**
 * 判断是否为空
 * @param {*} object 源对象
 */
export function isEmpty (value) {
  if (isArray(value)) {
    return value.length === 0
  }
  if (isObject(value)) {
    return isEmptyObject(value)
  }
  return !value
}

/**
* 本地存储 localStorage
*/
export const Storage = {
  set (key, val) {
    if (!key) return
    if (typeof val !== 'string') {
      val = JSON.stringify(val)
    }
    window.localStorage.setItem(key, val)
  },

  get (key) {
    if (!key) return
    if (window.localStorage.getItem(key) === 'true') {
      return true
    }
    if (window.localStorage.getItem(key) === 'false') {
      return false
    }
    const data = window.localStorage.getItem(key)
    return JSON.parse(data)
  },

  /**
  * 删除localStorage
  */
  remove (key) {
    if (!key) return
    window.localStorage.removeItem(key)
  }
}

/**
 * 生成唯一ID
 * 函数将生成类似 ix49sfsnt7514k5wpflyb5l2vtok9y66r 的ID
 */
export function guid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
      var r = Math.random() * 16 | 0,
          v = c == 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
  });
}